package com.easypermission.hddglibrary

import android.accounts.AccountAuthenticatorActivity
import android.util.Log
import androidx.fragment.app.FragmentActivity

object EasyPermission {
    private const val TAG = "InvisibleFragment"
    fun request(
        activity: FragmentActivity,
        vararg permissions: String,
        callback: PermissionCallback
    ) {
        val framentManager = activity.supportFragmentManager
        val existedFragment = framentManager.findFragmentByTag(TAG)
        val fragment = if (existedFragment != null) {
            Log.d("hhh","existedFragment != null")
            existedFragment as InvisibleFragment
        } else {
            Log.d("hhh","existedFragment == null")

            val invisibleFragment = InvisibleFragment()
            framentManager.beginTransaction().add(invisibleFragment, TAG).commitNow()
            invisibleFragment
        }
        fragment.requestNow(callback, *permissions)//*表示数组转换成可变长度参数传递
    }
}